<template>
  <div class="basic-info-user">
    <div class="user-box">
      <el-image :src="props.data.avatar" fit="cover" class="photo">
        <template #error>
          <div class="image-slot">
            <el-icon><icon-picture /></el-icon>
          </div>
        </template>
      </el-image>
      <div class="user-info">
        <template v-if="props.type === 'staff'">
          <p class="cell-box">
            <span class="name">{{ props.data.work_user_name }}</span>
            <span class="sex" :style="{ background: formatSex.bgColor }">{{ formatSex.name }}</span>
            <!-- <span class="tag">金牌导购</span> -->
          </p>
          <p class="text mt10">{{ formatTel(props.data.mobile) }}</p>
        </template>
        <template v-if="props.type === 'group'">
          <p class="name">{{ props.data.group_name }}</p>
          <p class="text">群主：{{ props.data.owner_username || '--' }}</p>
          <p class="text">群人数：{{ props.data.member_nums || '0' }}人</p>
        </template>
      </div>
    </div>
    <p v-if="props.type === 'group'" class="omit-text">群公告：{{ props.data.notice || '暂无' }}</p>
    <el-divider class="divider" />
    <Tags :tags="props.data.tag_info" />
    <div class="user-info-desc">
      <label class="title">{{ props.type === 'group' ? '群主所在部门' : '所在部门' }}：</label>
      <template v-if="props.data.department_info && props.data.department_info.length > 0">
        <span v-for="(item, index1) in props.data.department_info" :key="index1" class="word">{{ item.name }}</span>
      </template>
      <span v-else class="word">--</span>
    </div>
    <div class="user-info-desc">
      <label class="title">{{ props.type === 'group' ? '建群时间' : '入职时间' }}：</label>
      <span class="word">{{ props.data.induction_time || props.data.create_group_time || '--' }}</span>
    </div>
    <el-divider class="divider" />
    <div class="user-info-desc">
      <!-- <label class="title">{{ props.type === 'group' ? '客户表现' : '添加客户时间' }}：</label>
      <span class="word">{{ props.data.add_time || props.data.cust_show || '--' }}</span> -->
      <label class="title">{{  '添加客户时间' }}：</label>
      <span class="word">{{ props.data.add_time || '--' }}</span>
    </div>
    <div class="user-info-desc">
      <label class="title">{{ props.type === 'group' ? '入群时间' : '最近联系时间' }}：</label>
      <span class="word">{{ props.data.contact_time || props.data.join_time || '--' }}</span>
    </div>
    <div class="user-info-desc">
      <label class="title">{{ props.type === 'group' ? '退群时间' : '删除客户时间' }}：</label>
      <span class="word">{{ props.data.delete_time || props.data.sign_out_time || '--' }}</span>
    </div>
    <div v-if="props.type==='group'&&props.data?.contactMemberList?.length>0" class="group_contact">
      <div class="group_title">群客户联系人</div>
      <ul>
        <li v-for="item in props.data.contactMemberList" :key="item.id">
          <el-image class="user_icon" :src="item.avatar">
            <template #error>
              <el-icon><icon-picture /></el-icon>
            </template>
          </el-image>
          <div class="user_con">
            <div class="user_name">{{item.name}}</div>
            <div class="user_tel">
              {{item.is_quit==0 ? '入' :'退'}}群时间 
              {{item.is_quit==0 ? item.join_time :item.quit_at}}
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps, ref, reactive, computed, watch } from 'vue'
import { Picture as IconPicture } from '@element-plus/icons-vue'

import Tags from './Tags.vue'

import { formatTel } from '@/utils/utils'

interface Props {
  type: string
  data: any
}

const props = withDefaults(defineProps<Props>(), {
  type: 'staff',
  data: {}
})

const formatSex = computed(() => {
  if (props.data.sex === 1) return { name: '男', bgColor: '#74ddf4' }
  else if (props.data.sex === 2) return { name: '女', bgColor: '#f474bf' }
  else return { name: '未', bgColor: '#d9d9d9' }
})
</script>

<style lang="scss" scoped>
.basic-info-user {
  flex: 0 0 310px;
  width: 310px;
  padding: 10px 20px;
  background: #ffffff;
  border: 1px solid #eaeaea;
  box-sizing: border-box;

  .user-box {
    display: flex;
    align-items: center;

    .photo {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 60px;
      height: 60px;
      // background: #eaeaea;
      border-radius: 4px;
      vertical-align: middle;
      object-fit: cover;

      .image-slot {
        .el-icon {
          font-size: 36px;
        }
      }
    }
    .user-info {
      flex: auto;
      margin-left: 20px;

      p {
        margin: 0;
      }

      .cell-box {
        display: flex;
        align-items: center;

        .sex {
          display: flex;
          justify-content: center;
          align-items: center;
          width: 18px;
          height: 18px;
          margin-left: 5px;
          border-radius: 50%;
          font-size: 12px;
          color: #fff;
        }
        .tag {
          text-align: right;
          flex: auto;
          font-size: 14px;
          font-weight: 300;
          color: #696969;
        }
      }

      .name {
        font-size: 20px;
        font-weight: 500;
        color: #33302d;
        line-height: 21px;
      }
      .text {
        font-size: 14px;
        font-weight: 300;
        color: #696969;
        line-height: 18px;
      }

      .mt10 {
        margin-top: 10px;
      }
    }

    .el-dropdown {
      align-self: flex-start;
      .handle {
        text-align: center;
        width: 12px;
        cursor: pointer;
        .icon {
          width: 3px;
          height: auto;
        }
      }
    }
  }
  .omit-text {
    margin: 16px 0;
    font-size: 13px;
    font-weight: 300;
    color: #969696;
    line-height: 18px;
    -webkit-line-clamp: 2;
  }
  .divider {
    margin: 16px 0;
  }
  .user-info-desc {
    display: flex;
    margin-top: 16px;

    &:last-of-type {
      margin-bottom: 0;
    }

    .title {
      flex: 0 0 auto;
      font-size: 14px;
      font-weight: 300;
      color: #969696;
    }
    .word {
      flex: auto;
      font-size: 14px;
      font-weight: 300;
      color: #33302d;
    }
  }
  .group_contact{
    margin-top: 15px;
    .group_title{
      font-size: 16px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #33302D;
    }
    li{
      margin-top: 16px;
      display: flex;
      .user_icon{
        width: 36px;
        height: 36px;
        border-radius: 4px;
        margin-right: 10px;
      }
      .user_con{
        padding-bottom: 16px;
        border-bottom: 1px solid #EAEAEA;
        .user_name{
          font-size: 14px;
          font-family: STHeitiSC-Light, STHeitiSC;
          font-weight: 300;
          color: #33302D;
        }
        .user_tel{
          margin-top: 10px;
          font-size: 12px;
          font-family: STHeitiSC-Light, STHeitiSC;
          font-weight: 300;
          color: #969696;
        }
      }
    }
  }
}
</style>
